<template>
  <div id="forumpage"
       :style="{background: 'url('+bgimgBtn+')',backgroundRepeat: 'no-repeat',backgroundSize: '100% 100%'}">
    <div class="forum">
      <forumheader @searchFn="searchFn"></forumheader>
      <div class="rourmCenter">
        <div class="rourmCenter-centent">
          <div class="nexttitle" style="display: flex;align-items: center">
            <div style="flex: 1">
            <el-page-header @back="goBack" :content="title"></el-page-header>
            </div>
<!--            <p v-if="pageOption.type!=='search'">版主：{{username}}</p>-->
          </div>
          <div class="">
            <div class="centent-two" @click="gotolist(index)" v-for="(item,index) in arryList" :key="index">
              <div class="centent-two-title">
                <span>文章</span>
                <p>{{item.title}}</p>
              </div>
              <div class="centent-two-usertime">
                <span>发布人：{{item.user.realname}}</span>
                <span>发布时间：{{item.create_time}}</span>
              </div>
              <!--<div class="centent-two-desc">-->
              <!--伴随着三月的春风和充满希望的晨光，新疆436.79万名中小学和中职学校今天开学。上学错峰、进校排队、间隔一米、三次测温，新学期第一天，学生们除了校服、课本、书包，还有了新的配置：口罩和免洗消毒液-->
              <!--</div>-->
              <div class="centent-two-talk">
                <span class="talkSpan"><i class="iconfont iconpinglun"></i>{{item.comment_number}}</span>
                <span class="talkSpan"><i class="iconfont iconzanpress"></i>{{item.laud}}</span>
                <!--is_parents-->
              </div>
            </div>
          </div>
          <el-col :span="24" style="text-align: center">
            <el-pagination
                    background
                    layout="total, prev, pager, next"
                    :total="page.total"
                    :page-size="page.pagesize"
                    @current-change="handleSizeChange"
                    v-if="page.total">
            </el-pagination>
            <p v-else style="padding:60px 0;">版主未发布内容</p>
          </el-col>
        </div>
        <!--<div class="rourmCenter-right">-->
        <!--<modulelist></modulelist>-->
        <!--<modulecate></modulecate>-->
        <!--</div>-->
      </div>
    </div>
  </div>
</template>

<script>
  import bgimgBtn from '@/assets/imageAdmin/bgforue.png'
  import modulecate from '@/components/forum/modulecate'
  import modulelist from '@/components/forum/modulelist'
  import forumheader from '@/components/forum/headerforum'
  import {pagination} from '@/utils/util.js'
  import '@/assets/scss/forum.scss'
  import api from '@/utils/api.js'

  export default {
    components: {
      modulecate,
      modulelist,
      forumheader
    },
    data () {
      return {
        bgimgBtn: bgimgBtn,
        pageOption: this.$route.query,
        formData: {
          p: 1,
          plate_id: '',
          title: '',
          is_examine: 1
        },
        page: {
          pageindex: pagination.pageIndex,
          pagesize: pagination.pageSize,
          total: pagination.total
        },
        arryList: [],
        title: '',
        username: ''
      }
    },
    created () {
      if (this.$route.query.type === 'search') {
        this.formData.title = this.pageOption.search
        this.title = '搜索'
      } else {
        this.formData.plate_id = this.pageOption.id
        this.title = this.pageOption.title
      }
      this.InitFn()
    },
    methods: {
      InitFn () {
        this.formData.p = this.page.pageindex
        this.$fetch(api.forum_postings_index, this.formData).then((response) => {
          if (response.code === 0) {
            this.arryList = response.list.data
            this.page.total = response.list.total
            if (this.$route.query.type !== 'search') {
              this.username = response.plate.user.realname
            }
          } else {
          }
        }).catch((err) => {
          console.log(err)
        })
      },
      // 分页
      handleSizeChange (val) {
        this.page.pageindex = val
        this.InitFn()
      },
      gotolist (index) {
        this.$router.push('/forumdetail?type=1&id=' + this.arryList[index].id)
      },
      goBack () {
        this.$router.go(-1)
      },
      searchFn (option) {
        this.formData.title = option
        this.page.pageindex = 1
        this.InitFn()
      }
    },
    mounted () {
    }
  }
</script>


